package com.liuxinlong.modules.patent.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarCarouselReq;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.PatentCarousel;
import com.liuxinlong.modules.entity.PatentNotice;
import com.liuxinlong.modules.patent.controller.request.QueryPatentNoticeReq;
import com.liuxinlong.modules.patent.controller.request.UpdatePatentNoticeReq;
import com.liuxinlong.modules.patent.service.PatentCarouselService;
import com.liuxinlong.modules.patent.service.PatentNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 专利公告控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-09-15
 */
@RestController
@RequestMapping("/patent-notice")
public class PatentNoticeController {

    @Autowired
    private PatentNoticeService patentNoticeService;

    @Autowired
    private PatentCarouselService patentCarouselService;

    /**
     * 分页查询专利公告信息列表
     *
     * @param req 请求信息
     * @return 专利公告信息
     */
    @PostMapping("page")
    public BaseResp pagePatentNoticeInfo(@RequestBody QueryPatentNoticeReq req) {
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("startNum", req.getStartNum());
        queryParam.put("pageSize", req.getPageSize());
        queryParam.put("noticeType",req.getNoticeType());
        List<Map<String, Object>> dataList = patentNoticeService.queryPatentNoticeList(queryParam);
        int totalNum = patentNoticeService.getPatentNoticeCount(queryParam);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询专利公告信息列表成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增专利公告信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增专利公告", business = LogBusinessConstants.PATENT_NOTICE, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addPatentNotice(@RequestBody UpdatePatentNoticeReq req) {
        PatentNotice patentNotice = new PatentNotice();
        patentNotice.setNoticeType(req.getNoticeType());
        patentNotice.setContent(req.getContent());
        patentNotice.setUrl(req.getUrl());
        patentNotice.setRemark(req.getRemark());
        patentNoticeService.addPatentNotice(patentNotice);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增专利公告信息成功");
        return resp;

    }

    /**
     * 修改专利信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改专利公告", business = LogBusinessConstants.PATENT_NOTICE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updatePatentNotice(@RequestBody UpdatePatentNoticeReq req) {
        PatentNotice patentNotice = new PatentNotice();
        patentNotice.setId(req.getId());
        patentNotice.setNoticeType(req.getNoticeType());
        patentNotice.setContent(req.getContent());
        patentNotice.setUrl(req.getUrl());
        patentNotice.setRemark(req.getRemark());
        patentNoticeService.updatePatentNotice(patentNotice);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利公告信息成功");
        return resp;
    }

    /**
     * 删除专利信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除专利公告", business = LogBusinessConstants.PATENT_NOTICE, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deletePatentNotice(@RequestBody BaseDeleteReq req) {
        patentNoticeService.deletePatentNotice(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除专利公告信息成功");
        return resp;
    }

    /**
     * 分页查询轮播配置信息
     *
     * @param req 请求信息
     * @return 轮播配置信息列表
     */
    @PostMapping("/carousel-page")
    public BaseResp pageCarouselList(@RequestBody QueryBaseReq req) {
        Map<String,Object> queryParam = new HashMap<>();
        queryParam.put("startNum",req.getStartNum());
        queryParam.put("pageSize",req.getPageSize());
        List<Map<String,Object>> dataList = patentCarouselService.queryPatentCarouselList(queryParam);
        int total = patentCarouselService.getPatentCarouselCount(queryParam);
        BaseResp resp = new BaseResp();
        resp.setDataList(dataList);
        resp.setTotalNum(total);
        resp.setRetMessage("分页查询轮播信息成功");
        return resp;
    }

    /**
     * 新增轮播
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("/carousel-add")
    @LogAnnotation(value ="新增专利轮播",business = LogBusinessConstants.PATENT_TRENDS,operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp addCarousel(@RequestBody UpdateBarCarouselReq req) {
        PatentCarousel patentCarousel = new PatentCarousel();
        patentCarousel.setTitle(req.getTitle());
        patentCarousel.setShowIndex(req.getShowIndex());
        patentCarousel.setPicture(req.getPicture());
        patentCarousel.setRelation(req.getRelation());
        patentCarousel.setStartTime(req.getStartTime());
        patentCarousel.setEndTime(req.getEndTime());
        patentCarousel.setRemark(req.getRemark());
        patentCarouselService.addPatentCarousel(patentCarousel);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增专利轮播成功");
        return resp;
    }

    /**
     * 修改轮播信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("/carousel-update")
    @LogAnnotation(value ="修改专利轮播信息",business = LogBusinessConstants.PATENT_TRENDS,operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateCarousel(@RequestBody UpdateBarCarouselReq req) {
        PatentCarousel patentCarousel = new PatentCarousel();
        patentCarousel.setId(req.getId());
        patentCarousel.setTitle(req.getTitle());
        patentCarousel.setShowIndex(req.getShowIndex());
        patentCarousel.setPicture(req.getPicture());
        patentCarousel.setRelation(req.getRelation());
        patentCarousel.setStartTime(req.getStartTime());
        patentCarousel.setEndTime(req.getEndTime());
        patentCarousel.setRemark(req.getRemark());
        patentCarouselService.updatePatentCarousel(patentCarousel);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利轮播信息成功");
        return resp;
    }

    /**
     * 删除轮播信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("/carousel-delete")
    @LogAnnotation(value ="删除专利轮播信息",business = LogBusinessConstants.PATENT_TRENDS,operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteCarousel(@RequestBody BaseDeleteReq req) {
        patentCarouselService.deletePatentCarousel(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除专利轮播信息成功");
        return resp;
    }

    /**
     * 修改轮播状态
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("/carousel-status")
    @LogAnnotation(value ="修改轮播状态",business = LogBusinessConstants.PATENT_TRENDS,operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateCarouselStatus(@RequestBody BaseDeleteReq req) {
        patentCarouselService.updatePatentCarouselStatus(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改轮播状态成功");
        return resp;
    }

}
